package web.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;

public class Client {
	final static String ADDRESS = "127.0.0.1";
	final static int PORT = 7788;
	private static int j = 0;

	public static void main(String[] args) throws Exception, IOException {
		for (int i = 0; i < 40; i++) {
			//Thread.sleep(2000L);

			new Thread() {
				public void run() {

					try {
						Socket socket = null;
						BufferedReader in = null;
						PrintWriter out = null;
						socket = new Socket(ADDRESS, PORT);
						in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
						out = new PrintWriter(socket.getOutputStream(), true);

						// 向服务器端发送数据
						out.println("接收到客户端的请求数据..." + (j++));
						String response = in.readLine();
						System.out.println("Client: " + response);
					} catch (Exception e) {
						e.printStackTrace();
					}

				};
			}.start();
		}
		
		System.in.read();
	}
}